package com.bzframework.pro.service;

import com.bzframework.pro.constant.CommonConstants;
import com.bzframework.pro.entity.OrderEntity;
import com.bzframework.pro.model.school.SchoolHouseKeeperBatchResponse;
import com.bzframework.pro.model.school.student.StudentResponse;
import org.hswebframework.web.crud.service.GenericReactiveCrudService;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;

import java.time.Duration;

/**
 * @Author bingzhong
 * @Date 2025/3/21 10:50
 * @Description
 */
@Service
public class OrderService extends GenericReactiveCrudService<OrderEntity, String> {


    /**
     * 根据 id 获取学员
     * @param accessToken
     * @param studentId
     * @return
     */
    public Mono<StudentResponse> fetchStudentById(String accessToken, String studentId) {

        return WebClient
                .create(CommonConstants.SCHOOL_HOUSEKEEPER_PRODUCTION_URL)
                .get()
                .uri(uriBuilder -> uriBuilder
                        .path("/user/get_student")
                        .queryParam("access_token", accessToken)
                        .queryParam("student_id", studentId)
                        .build())
                .retrieve()
                .bodyToMono(StudentResponse.class)
                .timeout(Duration.ofSeconds(15)) // 单独请求超时
                .retryWhen(Retry.backoff(3, Duration.ofSeconds(1))); // 指数退避重试;;

    }


}
